package com.jijuxie.agent.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jijuxie.agent.domain.Agent;
import com.jijuxie.agent.service.IAgentService;
import com.jijuxie.common.core.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 经纪人信息控制器
 * 用于处理经纪人信息查询相关接口
 *
 * @author jijuxie
 */
@RestController
@RequestMapping("/agent/info")
public class AgentInfoController {

    @Autowired
    private IAgentService agentService;

    /**
     * 获取经纪人列表
     * 用于房源分配等功能选择经纪人
     *
     * @param realName 经纪人姓名（模糊匹配）
     * @return 经纪人列表
     */
    @GetMapping("/list")
    public R<List<Agent>> list(@RequestParam(required = false) String realName) {
        LambdaQueryWrapper<Agent> queryWrapper = new LambdaQueryWrapper<>();
        
        // 添加姓名模糊查询条件
        if (StringUtils.isNotBlank(realName)) {
            queryWrapper.like(Agent::getRealName, realName);
        }
        
        // 只查询状态正常的经纪人
        queryWrapper.eq(Agent::getStatus, "1");
        
        // 按ID排序
        queryWrapper.orderByAsc(Agent::getAgentId);
        
        List<Agent> list = agentService.list(queryWrapper);
        return R.ok(list);
    }
} 